package com.sokal.easycare.modules.sys.entity;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.sokal.easycare.common.persistence.DataEntity;
import com.sokal.easycare.common.utils.Collections3;
import com.sokal.easycare.modules.position.entity.Duty;

/**
 * 用户User POJO定义
 * 
 * @author Yangmin
 *
 */
public class MainUser extends DataEntity<MainUser> {

	private static final long serialVersionUID = 1L;

	private String uuid; // uuid
	private String loginName; // user_name
	private String password; // 采用不可逆密文存储
	private String nickname; // nickname
	private String sex; // sex
	private long acctId; // acct_id
	private long gisLocationId; // gis_location_id
	private String portraitPhoto; // portrait_photo
	private String mobileUserNbr; // mobile_user_nbr
	private Date registDate; // regist_date
	private String bonus; // 用户充值1元积分增加1分。 积分消费-待后续考虑。
	private String aucOrg; // 一般是组织对应分公司的公章，个人对应手写签名的图片。
	private String status; // 0实名认证未提交1待审核2审核通过3审核失败4角色申请提交5审核通过6审核失败 
	private String isSmsNotify; // Value Label Y 是 N 否 缺省是N
	private String isEmailNotify; // Value Label Y 是 N 否 缺省是N
	private String locationDesc; // location_desc
	private String qqOpenId; // qq_open_id
	private String wxOpenId; // wx_open_id
	private String sinaUid; //sina_uid

	private Office office; // 归属部门
	private Role role; // 根据角色查询用户条件
	private Duty duty;// 根据查询用户条件
	private Area area;// 用户区域

	// 用户类型: 90R 注册用户 90A内部员工90G协议供货商90S自由人销售90M原厂90I监管者90Z系统管理员90W售后师傅90D设计师
	// 90C项目经理
	private String userType;

	private List<Role> roleList = Lists.newArrayList(); // 拥有角色列表

	private List<Duty> dutyList = Lists.newArrayList(); // 拥有岗位列表

	private String oldLoginName;// 原登录名
	private String newPassword; // 新密码

	public MainUser() {
		super();
	}

	public MainUser(String id) {
		super(id);
	}

	public MainUser(String id, String userName) {
		super(id);
		this.loginName = userName;
	}

	public MainUser(Role role) {
		super();
		this.role = role;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	@JsonIgnore
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public long getAcctId() {
		return acctId;
	}

	public void setAcctId(long acctId) {
		this.acctId = acctId;
	}

	public long getGisLocationId() {
		return gisLocationId;
	}

	public void setGisLocationId(long gisLocationId) {
		this.gisLocationId = gisLocationId;
	}

	public String getPortraitPhoto() {
		return portraitPhoto;
	}

	public void setPortraitPhoto(String portraitPhoto) {
		this.portraitPhoto = portraitPhoto;
	}

	public String getMobileUserNbr() {
		return mobileUserNbr;
	}

	public void setMobileUserNbr(String mobileUserNbr) {
		this.mobileUserNbr = mobileUserNbr;
	}

	public Date getRegistDate() {
		return registDate;
	}

	public void setRegistDate(Date registDate) {
		this.registDate = registDate;
	}

	public String getBonus() {
		return bonus;
	}

	public void setBonus(String bonus) {
		this.bonus = bonus;
	}

	public String getAucOrg() {
		return aucOrg;
	}

	public void setAucOrg(String aucOrg) {
		this.aucOrg = aucOrg;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@JsonIgnore
	public String getIsSmsNotify() {
		return isSmsNotify;
	}

	public void setIsSmsNotify(String isSmsNotify) {
		this.isSmsNotify = isSmsNotify;
	}

	@JsonIgnore
	public String getIsEmailNotify() {
		return isEmailNotify;
	}

	public void setIsEmailNotify(String isEmailNotify) {
		this.isEmailNotify = isEmailNotify;
	}

	@JsonIgnore
	public String getLocationDesc() {
		return locationDesc;
	}

	public void setLocationDesc(String locationDesc) {
		this.locationDesc = locationDesc;
	}

	public String getQqOpenId() {
		return qqOpenId;
	}

	public void setQqOpenId(String qqOpenId) {
		this.qqOpenId = qqOpenId;
	}

	public String getWxOpenId() {
		return wxOpenId;
	}

	public void setWxOpenId(String wxOpenId) {
		this.wxOpenId = wxOpenId;
	}

	@JsonIgnore
	public Office getOffice() {
		return office;
	}

	public void setOffice(Office office) {
		this.office = office;
	}

	@JsonIgnore
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@JsonIgnore
	public List<Role> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	@JsonIgnore
	public boolean isAdmin() {
		return isAdmin(this.id);
	}

	@JsonIgnore
	public static boolean isAdmin(String id) {
		return id != null && "1".equals(id);
	}

	@JsonIgnore
	public List<String> getRoleIdList() {
		List<String> roleIdList = Lists.newArrayList();
		for (Role role : roleList) {
			roleIdList.add(role.getId());
		}
		return roleIdList;
	}

	public void setRoleIdList(List<String> roleIdList) {
		roleList = Lists.newArrayList();
		for (String roleId : roleIdList) {
			Role role = new Role();
			role.setId(roleId);
			roleList.add(role);
		}
	}

	@JsonIgnore
	public String getRoleNames() {
		return Collections3.extractToString(roleList, "name", ",");
	}

	@JsonIgnore
	public String getOldLoginName() {
		return oldLoginName;
	}

	public void setOldLoginName(String oldLoginName) {
		this.oldLoginName = oldLoginName;
	}

	@JsonIgnore
	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	@JsonIgnore
	public List<Duty> getDutyList() {
		return dutyList;
	}

	public void setDutyList(List<Duty> dutyList) {
		this.dutyList = dutyList;
	}

	@JsonIgnore
	public Duty getDuty() {
		return duty;
	}

	public void setDuty(Duty duty) {
		this.duty = duty;
	}

	public String getSinaUid() {
		return sinaUid;
	}

	public void setSinaUid(String sinaUid) {
		this.sinaUid = sinaUid;
	}

	/**
	 * 用户类型
	 */
	public static enum UserType {

		// 用户类型: 90R 注册用户 90A内部员工90G协议供货商90S自由人销售90M原厂90I监管者90Z系统管理员90W售后师傅90D设计师 90C项目经理
		REGISTERED_USER("90R", "注册用户"), EMPLOYEES("90A", "内部员工"), SUPPLIER("90G", "协议供货商"), SALESMAN("90S",
				"自由人销售"), FACTORY("90M", "原厂"), SUPERVISORS("90I", "监管者"), SYS_ADMIN("90Z",
						"系统管理员"), AFTER_SALES("90W", "售后师傅"), DESIGNER("90D", "设计师"), PM("90C", "项目经理");

		private String value = null;
		private String desc = null;

		private UserType(String v, String desc) {
			this.value = v;
			this.desc = desc;
		}

		public String value() {
			return this.value;
		}

		public String desc() {
			return this.desc;
		}

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}

		public String getDesc() {
			return desc;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}
		
		
	}
}
